package home.projects.misc;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class SerialRegexTest {

   public static void main(final String[] args) {
      long now = System.currentTimeMillis();
      File inFile = new File("c:/a.txt");
      File outFile = new File("c:/b.txt");
      new RegexProcessor(inFile, outFile).process();
      System.out.println(System.currentTimeMillis() - now);
   }
   
}

class RegexProcessor {
   
   private final String lineSeparator;
   
   private final File inFile;
   
   private final File outFile;
   
   public RegexProcessor(File inFile, File outFile) {
      this.inFile = inFile;
      this.outFile = outFile;
      this.lineSeparator = System.getProperty("line.separator");
   }
   
   public void process() {
      PrintWriter out = null;
      Scanner in = null;
      String s = null;
      try {
         in = new Scanner(inFile);
         out = new PrintWriter(outFile);
         while(in.hasNext()) {
            s = in.next();
            
            for(int i = 0; i < 10000; ++i) {}
            out.write(s + Math.random());
            out.write(lineSeparator);
         }
      } catch(IOException ioe) {
         throw new RuntimeException(ioe);
      } finally {
         if(in != null) {
            in.close();
            if(in.ioException() != null) {
               in.ioException().printStackTrace();
            }
         }
         if(out != null) {
            out.close();
            if(out.checkError()) {
               System.out.println("Prblem when closing out stream!");
            }
         }
      }
   }
   
}
